import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";
import store from '../store/index'
Vue.use(VueRouter);
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, resolve, reject) {
    if ( resolve || reject ) return originalPush.call(this, location, resolve, reject)
    return originalPush.call(this, location).catch((e)=>{e})
}

const routes = [
  {
    path:"/login",
    name:"login",
    component:()=>import('../views/LoginView.vue')
  },
  {
    path: "/",
    name: "home",
    component: HomeView,
  },
  {
    path:"/video",
    name:"video",
    component:()=>import('../views/VideoView.vue')

  },
  {
    path:"/type",
    name:"type",
    component:()=>import('../views/TypeView.vue')

  },
  {
    path:"/talk",
    name:"talk",
    meta:{name:1},
    component:()=>import('../views/TalkView.vue'),
    beforeEnter:(to,from,next)=>{
      
      let token = store.state.token
      console.log(this)
      if(token){
        next()
      }else{
        next({name:"login",params:{id:"talk"}})
      }
    }

  },
  {
    path:"/mine",
    name:"mine",
    meta:{name:2},
    component:()=>import('../views/MineView.vue'),
    beforeEnter:(to,from,next)=>{
      let token = store.state.token
      if(token){
        next()
      }else{
        next({name:"login",params:{id:"mine"}})
      }
    }

  },
  
  {
    path: "/about",
    name: "about",
    component: () =>
      import("../views/AboutView.vue"),
  },

];

const router = new VueRouter({
  routes,
});
//权限管理


export default router;
